package com.toy.abash.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.toy.abash.domain.Abash;
import com.toy.abash.domain.Reply;
import com.toy.abash.service.AbashManager;
import com.toy.abash.service.ReplyManager;
import com.toy.core.dao.support.Page;
import com.toy.core.util.StringUtils;
import com.toy.core.web.BaseController;

@Controller
@RequestMapping("/abash/admin")
public class ConsoleController extends BaseController {
	
	public static final String MODULE_PREFIX = "/abash/console";
	
	@Autowired
	private AbashManager abashManager;
	
	@Autowired
	private ReplyManager repliesManager;
	
	//管理页面主页面
	@RequestMapping("/console")
	public String navConsoleHome(){
		return MODULE_PREFIX + "/console_main";
	}
	
	//管理页面左侧导航
	@RequestMapping("/consoleLeft")
	public String navConsoleLeft(Model model){
		return MODULE_PREFIX + "/console_left";
	}
	
	//翻页显示所有糗事
	@RequestMapping("/findPostsPaged")
	public String findPostsPaged(String pageNo,String pageSize,Model model){
		int _pageNo = StringUtils.parseString(pageNo, 1);
		int _pageSize = StringUtils.parseString(pageSize, 20);
		Page<Abash> page = abashManager.findPaged(_pageNo, _pageSize);
		model.addAttribute("page", page);
		return MODULE_PREFIX + "/posts/posts_list";
	}
	
	//翻页显示所有回复
	@RequestMapping("/findRepliesPaged")
	public String findRepliesPaged(String pageNo,String pageSize,Model model){
		int _pageNo = StringUtils.parseString(pageNo, 1);
		int _pageSize = StringUtils.parseString(pageSize, 20);
		Page<Reply> page = repliesManager.findPaged(_pageNo, _pageSize);
		model.addAttribute("page", page);
		return MODULE_PREFIX + "/replies/replies_list";
	}
	
}
